/******************************************************************************
 *  _____     _____
 *  \  __\    \  __\
 *   \ \_\\    \ \_\\
 *    \  __\SS  \  __\roject
 *     \_\       \_\
 *
 * Mateusz Maciąg, Rafał Urbański
 * Komputerowe Systemy Sterowania
 *****************************************************************************/

#include "GainControllerDesigner.h"
#include "ui_GainControllerDesigner.h"

#include <QMessageBox>

#include <iostream>
#include <string>

using namespace std;
using namespace RafMat::SimInterface;

GainControllerDesigner::GainControllerDesigner(QWidget *parent) :
    ControllerDesigner(parent),
    ui(new Ui::GainControllerDesigner)
{
    ui->setupUi(this);
}

GainControllerDesigner::~GainControllerDesigner()
{
    delete ui;
    std::cout << "Usunieto GainControllerDesigner";
}

void GainControllerDesigner::attachController(RafMat::SimInterface::IConfigurableSPtr ctrl)
{
    m_controllerConf = ctrl;

    double gain;

    try
    {
        string tmpStr = m_controllerConf->getParameter("gain");
        gain = QString::fromStdString(tmpStr).toDouble();
    }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
        return;
    }

    ui->gainBox->setValue(gain);
}

void GainControllerDesigner::applySettings()
{
    try
    {
         m_controllerConf->setParameter("gain", ui->gainBox->text().toStdString());
    }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}
